 const ajax={
    get:(url,callback,data)=>{
        const x = new XMLHttpRequest();
        let str="";
        if(data){
             str = Object.keys(data).map(item =>`${item}=${data[item]}`).join('&');
        }
        x.open('get',url+"?"+str);
        x.send();
        x.onreadystatechange=()=>{
            if(x.readyState===4){
                callback (x.response);
            }
            
        }
    },
    post:(url,callback,data)=>{
        const x = new XMLHttpRequest();
        let str="";
        if(data){
             str = Object.keys(data).map(item =>`${item}=${data[item]}`).join('&');
        }
        x.open('get',url);
        xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
        x.send(str);
        x.onreadystatechange=()=>{
            if(x.readyState===4){
                callback (x.response);
            }
        }

    }
}


export default ajax;